package com.mofeng.myshop.domain.dto;

import com.baomidou.mybatisplus.annotation.TableField;
import com.mofeng.myshop.domain.dto.base.BaseDto;
import com.mofeng.myshop.domain.po.Commodity;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;

@Data
@AllArgsConstructor
@NoArgsConstructor
@ToString(callSuper = true)
@EqualsAndHashCode(callSuper = true)
public class CommodityDto extends BaseDto {
    @Schema(description = "商品图片路径")
    private String image;
    @Schema(description = "小图标")
    private String iconImage;
    @Schema(description = "商品代码")
    private String code;
    @Schema(description = "商品基础价格")
    private Double basePrice;
    @Schema(description = "质量倍率,会用(质量数量-1)*此倍率，然后加在原价格上")
    private Double multiplierUp;
    @Schema(description = "等级倍率, 会用等级*此倍率，然后加在原价格上")
    private Double levelUp;
    @Schema(description = "等级上限 没有则空")
    private Integer levelTop;
    @Schema(description = "商品价格")
    private Double price;
    @Schema(description = "是否热点商品 0不是 1是")
    private String hot;
    @Schema(description = "折扣，小数")
    private Double discount;
    @Schema(description = "商品类别ID")
    private Long commodityCategoryId;
    @Schema(description = "商城ID")
    private Long projectId;

    @Schema(description = "虚拟删除状态， 0 存在  1删除")
    private String delete;

    public Commodity toCommodity() {
        Commodity commodity = new Commodity();
        toBaseEntity(commodity);
        if (this.image != null) {
            commodity.setImage(this.image);
        }
        if (this.iconImage != null) {
            commodity.setIconImage(this.iconImage);
        }
        if (this.code != null) {
            commodity.setCode(this.code);
        }
        if (this.basePrice != null) {
            commodity.setBasePrice(this.basePrice);
        }
        if (this.multiplierUp != null) {
            commodity.setMultiplierUp(this.multiplierUp);
        }
        if (this.levelUp != null) {
            commodity.setLevelUp(this.levelUp);
        }
        if (this.levelTop != null) {
            commodity.setLevelTop(this.levelTop);
        }
        if (this.price != null) {
            commodity.setPrice(this.price);
        }
        if (this.commodityCategoryId != null) {
            commodity.setCommodityCategoryId(this.commodityCategoryId);
        }
        if (this.projectId != null) {
            commodity.setProjectId(this.projectId);
        }
        if (this.hot != null) {
            commodity.setHot(this.hot);
        }
        if (this.discount != null) {
            commodity.setDiscount(this.discount);
        }
        if (this.delete != null) {
            commodity.setDelete(this.delete);
        }
        return commodity;
    }
}

